package com.kalix.jyksh.proint.biz;


import com.kalix.framework.core.impl.biz.GenericBizServiceImpl;
import com.kalix.framework.core.util.ConfigUtil;
import com.kalix.ksh.proint.api.biz.IRunSitBeanService;
import com.kalix.ksh.proint.api.dao.IRunSitBeanDao;
import com.kalix.ksh.proint.api.model.InfUtil;
import com.kalix.jyksh.proint.entities.RunSitBean;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Wanghw on 2018/10/10.
 * 骨干线路的实时运行情况
 */
public class RunSitBeanServiceImpl extends GenericBizServiceImpl<IRunSitBeanDao, RunSitBean> implements IRunSitBeanService {
    public RunSitBeanServiceImpl(){
        super.init(RunSitBean.class.getName());
    }
    public static String wsIp = (String) ConfigUtil.getConfigProp("FREEBOARD_IP","config.ksh.portconf");
    public static String wsPort =(String)ConfigUtil.getConfigProp("FREEBOARD_PORT","config.ksh.portconf");

    /**
     *
     * 功能描述: 获取骨干线路服务的数据
     *
     * @auther: Whw
     * @date: 2019/1/14 0014 17:18
     * @param:
     * @return:
     */
//    public String getValue() {
//        String sql = "select ru from RunSitBean ru";
//        List<RunSitBean> list = dao.find(sql);
//        JSONArray str = new JSONArray();
//        for (int i = 0; i < list.size(); i++) {
//            String uuid = list.get(i).getUuid();
//            String name = list.get(i).getName();
//            //总流量
//            String url = "http://"+wsIp+":"+wsPort+"/metrics/Metrics.moPath=\"Line.domain=\"defaultEngine\",uuid=\""+uuid+"\"\",name=\"ifPercent\"?fresh=1860 ";
//            double number = getData(url);
//            //带宽占用比
//            String url2 = "http://"+wsIp+":"+wsPort+"/metrics/Metrics.moPath=\"Line.domain=\"defaultEngine\",uuid=\""+uuid+"\"\",name=\"ifOctets\"?fresh=1860 ";
//            double number2 = getData(url2);
//            JSONObject jobj =new JSONObject();
//            jobj.put("name",name);
//            jobj.put("version",number);
//            jobj.put("location",number2);
//            str.put(jobj);
//        }
//        JSONObject obj = new JSONObject();
//        obj.put("title","骨干线路的实时运行情况");
//        JSONArray thead = new JSONArray();
//        JSONObject obj1 = new JSONObject();
//        obj1.put("name","设备名称");
//        obj1.put("width","100px");
//        JSONObject obj2 = new JSONObject();
//        obj2.put("name","总流量(M)");
//        obj2.put("width","100px");
//        JSONObject obj3 = new JSONObject();
//        obj3.put("name","带宽占用比(%)");
//        obj3.put("width","100px");
//        thead.put(obj1);
//        thead.put(obj2);
//        thead.put(obj3);
//        obj.put("title","骨干线路的实时运行情况");
//        obj.put("thead",thead);
//        obj.put("data",str);
//        String stri =obj.toString();
//        return stri;
//    }

    /**
     *
     * 功能描述: 调用获取服务数据
     *
     * @auther: Whw
     * @date: 2019/1/14 0014 17:18
     * @param:
     * @return:
     */
    public  double getData(String url){
        String  data= InfUtil.interfaceUtil(url,"");
        JSONObject obj = new JSONObject(data);
        double min= obj.getJSONObject("value").getDouble("value");
        return min;
    }
}

